//
//  WLLStatusBottomView.swift
//  WLLWeibo
//
//  Created by 王乐乐 on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class WLLStatusBottomView: UIView {
    var retweetButton :UIButton?
   var commentButton:UIButton?
   var unlikeButton:UIButton?
   //供外界赋值
    var statusViewModel :WLLStatusViewModel?{
        didSet{

            retweetButton?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            
            commentButton?.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            
            unlikeButton?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
        }
    }
    
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - 设置界面
    func setupUI()  {
//        backgroundColor = RandomColor()
        backgroundColor  = BottomColor
        retweetButton      = addChildButtons("timeline_icon_retweet", title: "转发")
        commentButton   = addChildButtons("timeline_icon_comment", title: "评论")
        unlikeButton         =   addChildButtons("timeline_icon_unlike", title: "赞")
        
        let lineOne = addChildLines()
        let lineTwo = addChildLines()
        
        //添加约束
        retweetButton!.snp_makeConstraints { (make) in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        commentButton!.snp_makeConstraints { (make) in
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(unlikeButton!)
        }
        unlikeButton!.snp_makeConstraints { (make) in
            make.leading.equalTo(commentButton!.snp_trailing)
            make.top.bottom.trailing.equalTo(self)
        }
        lineOne.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        lineTwo.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        

    }
    /**
     封装创建按钮的方法
     */
    func addChildButtons(imageName:String,title:String) -> UIButton {
        
        let btn = UIButton()
        //背景图
  
        

        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        //图片
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        //添加按钮
        addSubview(btn)
        return btn
        
    }
    func addChildLines() -> UIImageView {
        let img = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(img)
        return img
    }
    
    
}

